package initialize

import (
	"github.com/mark3labs/mcp-go/server"
	"mcp-demo/internal/global"
	"mcp-demo/internal/mcp"
	"mcp-demo/internal/middleware"
)

// McpRun 运行MCP服务
func McpRun() *server.SSEServer {
	config := global.CONFIG.MCP

	s := server.NewMCPServer(
		config.Name,
		config.Version,
		//server.WithRecovery(),
		server.WithToolHandlerMiddleware(middleware.ToolErrorMiddleware),
	)

	global.MCP_SERVER = s

	mcp.RegisterAllTools(s)

	return server.NewSSEServer(s,
		server.WithSSEEndpoint(config.SSEPath),         // SSE
		server.WithMessageEndpoint(config.MessagePath), // Http
		server.WithBaseURL(config.UrlPrefix))
}
